package com.xiaocikuai.smallchunks.utils.ListStringUtil;

import lombok.experimental.UtilityClass;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;


@UtilityClass
public class ListStringUtil {

    //字符串转换为列表
    static public List<Integer> idsToList(String id) {
        return Arrays.stream(id.substring(1, id.length() - 1).split(","))
                .map(Integer::parseInt)
                .toList();

    }

    //列表转换为字符串
    static public String listToIds(List<Integer> inputList) {
        StringBuilder stringBuilder = new StringBuilder("[");
        for (int i = 0; i < inputList.size(); i++) {
            stringBuilder.append(inputList.get(i));
            if (i!= inputList.size() - 1) {
                stringBuilder.append(",");
            }
        }
        stringBuilder.append("]");
        return stringBuilder.toString();
    }

}
